<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>修改员工页面</h1>
<form action="">
    <input type="text" name="id" placeholder="id" :value="emp.id" readonly>
    <input type="text" name="name" placeholder="名字" :value="emp.name">
    <input type="text" name="sal" placeholder="工资" :value="emp.sal">
    <input type="text" name="job" placeholder="工作" :value="emp.job">
    <input type="button" value="修改" @click="update()">
</form>
<script src="js/vue.min.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"form",
        data:{
            emp:{}
        },
        created:function () {
            //获取地址栏中的id
            let id = location.search.split("=")[1];
            //通过id查询员工的所有信息
            axios.get("/selectById?id="+id).then(function (response) {
                //把查询回来的员工信息赋值给员工对象.
                v.emp = response.data;
            })
        },
        methods:{
            update(){
                //得到form表单里面的数据
                let data = new FormData(document.querySelector("form"));
                axios.post("/update",data).then(function (response) {
                    alert("修改完成!");
                    location.href="/list.html";
                })
            }
        }
    })
</script>
</body>
</html>